home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / stdg44.exe / lha / LINES.C < prev    next >
C/C++ Source or Header  |  1994-01-10  |  1KB  |  55 lines

  1. #include <stdio.h>
  2. #include "stdg.h"
  3.  
  4. /* this program tests the drawing of some straight lines. */
  5.  
  6. point   p0, p1, p2, p3, p4;
  7.  
  8. void resize(window *w)  /* recalculate what the window looks like */
  9. {
  10.     rectangle r = w->b->r;
  11.  
  12.     p0 = pt(dx(r)/2,dy(r)/2);
  13.     p1 = pt(20,20);
  14.     p2 = pt(20,r.max.y-20);
  15.     p3 = pt(r.max.x-20,r.max.y-20);
  16.     p4 = pt(r.max.x-20,20);
  17. }
  18.  
  19. void redraw(window *w)  /* this function knows how to draw the window */
  20. {
  21.     fill_rect(w->b, w->b->r, WHITE); /* clear window */
  22.  
  23.     draw_line(w->b, p1, p2, RED);
  24.     draw_line(w->b, p2, p3, GREEN);
  25.     draw_line(w->b, p3, p4, BLUE);
  26.     draw_line(w->b, p4, p1, BLACK);
  27.  
  28.     draw_line(w->b, p0, addp(p1,pt(+2,+2)), BLUE);
  29.     draw_line(w->b, p0, addp(p2,pt(+2,-2)), BLACK);
  30.     draw_line(w->b, p0, addp(p3,pt(-2,-2)), RED);
  31.     draw_line(w->b, p0, addp(p4,pt(-2,+2)), GREEN);
  32.  
  33.     invert_rect(w->b, insetr(w->b->r,4));   /* inverting colours is fun */
  34.  
  35.     gflush();
  36. }
  37.  
  38. int main(int argc, char **argv)
  39. {
  40.     int c;
  41.     mouse m;
  42.     window *w;
  43.  
  44.     ginit("Sample", NULL, NULL);
  45.  
  46.     w = new_window("Lines", rect(0,0,0,0), Titlebar+Resize+Maximize);
  47.     set_winfns(w, NULL, &resize, &redraw);
  48.     show_window(w);
  49.  
  50.     while(1)
  51.         can_event();
  52.  
  53.     return 0;
  54. }
  55.